<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Agendaadm extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 */
	public function index(){
		$this->mng_agenda();
	}

//------------------------------------------------------------------------------------------->Agenda{
	function tulis_agenda($mode=""){
		if($mode=="error"){
			$pesan="Kesalahan, Field Pada Form Agenda Harus Diisi";
		}elseif($mode=="sukses"){
			$pesan="Agenda Berhasil Disimpan, <a href='".site_url('paneladm/agendaadm/mng_agenda')."'>View Agenda</a>";
		}else{
			$pesan="";	
		}
		$data['mode']  = $mode;
		$data['pesan'] = $pesan;
		$this->load->view('admin/agendaadm/admin-tulis-agenda',$data);
	}
	
	function mng_agenda($mode="noerror",$cari_kategori="null",$cari_deskripsi="null",$hari="0",$bulan="0",$tahun="0",$page=0){
		 
		if($mode=="error"){
			$pesan="Kesalahan, field pada form agenda harus diisi";
		}elseif($mode=="update"){
			$pesan="Agenda berhasil diperbaharui";
		}elseif($mode=="delete"){
			$pesan="Data agenda berhasil dihapus";
		}else{
			$pesan="";	
		}		
		
		$cari_kategori 	= mySQL_escape_string($this->input->post('cari_kategori'));
		if($cari_kategori==null) $cari_kategori = "null";
		$cari_deskripsi	= mySQL_escape_string($this->input->post('cari_deskripsi'));
		if($cari_deskripsi==null||$cari_deskripsi=="") $cari_deskripsi = "null";
		if($cari_kategori=="date"){
			$cari_deskripsi = "null";
			$hari			= mySQL_escape_string($this->input->post('hari'));
			$bulan			= mySQL_escape_string($this->input->post('bulan'));
			$tahun			= mySQL_escape_string($this->input->post('tahun'));
			if($hari==null) $hari= "0";
			if($bulan==null) $bulan= "0";
			if($tahun==null) $tahun= "0";
		}else{
			$hari= "0";
			$bulan= "0";
			$tahun= "0";	
		}
		
		$data['kategori'] = $cari_kategori;
		$data['deskripsi'] = $cari_deskripsi;
		$data['hari'] = $hari;
		$data['bulan'] = $bulan;
		$data['tahun'] = $tahun;
		
			  $this->load->library('pagination');
			  $this->load->model('tbl_agenda');	  
			  $banyak = $this->tbl_agenda->hitung_all($data);
			  $base_url = base_url();
			  $config['base_url'] = $base_url.'paneladm/agendaadm/mng_agenda/'.$mode.'/'.$cari_kategori.'/'.$cari_deskripsi.'/'.$hari.'/'.$bulan.'/'.$tahun.'/';
			  $config['total_rows'] = $banyak;
			  $config['per_page'] = '10'; 
			  $config['cur_page'] = $page;
			  $this->pagination->initialize($config);
			  
		$data['mode']  = $mode;
		$data['pesan'] = $pesan;
		$data['jumlah']= $banyak;
		$data['query'] = $this->tbl_agenda->load_admin($data,$config['cur_page']);	
        $this->load->view('admin/agendaadm/admin-mng-agenda', $data);
    }
	
	function input_agenda() {
		$judul  	= mySQL_escape_string($this->input->post('agenda_judul'));
		$isi		= mySQL_escape_string($this->input->post('agenda_isi'));
		$date		= mySQL_escape_string($this->input->post('agenda_tanggal'));
		$tipe		= mySQL_escape_string($this->input->post('agenda_tipe'));
		if(empty($judul) || empty($isi) || empty($date) || empty($tipe)){
			redirect('paneladm/agendaadm/tulis_agenda/error');
		}
		$judul =strip_tags(trim($judul));
		$isi =strip_tags(trim($isi));
		$date =strip_tags(trim($date));
		
		$this->load->model('tbl_agenda');
        $this->tbl_agenda->add($judul,$isi,$date, $tipe);
		redirect('paneladm/agendaadm/tulis_agenda/sukses');
    }
	
	function multi_hapus_agenda(){
		if (isset($_POST['delete'])){
		$cekbok = $this->input->post('cekbok');
		if($cekbok==""){
		redirect('paneladm/agendaadm/mng_agenda');
		}
		$jumlah = count($cekbok);
		$this->load->model('tbl_agenda');
		for($i=0;$i<$jumlah;$i++){
		 $this->tbl_agenda->delete($cekbok[$i]); 
		}
		}
		redirect('paneladm/agendaadm/mng_agenda/delete');
	}
	
	function edit_agenda($id) {
	    $this->load->model('tbl_agenda');
		$data['query'] = $this->tbl_agenda->edit($id);	
        $this->load->view('admin/agendaadm/admin-edit-agenda', $data);
    }
	
	function update_agenda() {
		$judul 	= mySQL_escape_string($this->input->post('agenda_judul'));
		$isi 	= mySQL_escape_string($this->input->post('agenda_isi'));
		$date	= mySQL_escape_string($this->input->post('agenda_tanggal'));
		$tipe	= mySQL_escape_string($this->input->post('agenda_tipe'));
		$id		= mySQL_escape_string($this->input->post('id'));
		if(empty($judul) || empty($isi) || empty($date) || empty($tipe)){
			redirect('paneladm/agendaadm/mng_agenda/error');
		}
		$judul =strip_tags(trim($judul));
		$isi =strip_tags(trim($isi),"<br>");
		$date =strip_tags(trim($date));
	    $this->load->model('tbl_agenda');
		$data['query'] = $this->tbl_agenda->update($id, $judul, $isi, $date, $tipe);	
        redirect('paneladm/agendaadm/mng_agenda/update');
    }
	
	function hapus_agenda($id){
		$this->load->model('tbl_agenda');
		$this->tbl_agenda->delete($id); 
		redirect('paneladm/agendaadm/mng_agenda/delete');
	}
//-------------------------------------------------------------------------------------------->Agenda}
}